#include "propertiesdialog.h"

#define UNKNOWN "未知"
#define COUNTRY "乡村"
#define CITY "城市"
#define EXPRESSWAY "高速公路"

PropertiesDialog::PropertiesDialog(QWidget *parent)
    : QWidget(parent)
{
//    this->setWindowTitle("属性编辑区");
    initUI();
    initSignalSlot();
//    this->setFixedWidth(500);
}

void PropertiesDialog::initUI()
{
    QGridLayout *pGridLayout = new QGridLayout();

    QLabel *plabelID = new QLabel("ID:",this);
    m_pLabel_ID = new QLabel(this);
    QLabel *plabelName = new QLabel("名称:", this);
    m_pLineEdit_Name = new QLineEdit(this);
    pGridLayout->addWidget(plabelID, 0, 0);
    pGridLayout->addWidget(m_pLabel_ID, 0, 1);
    pGridLayout->addWidget(plabelName, 0, 2);
    pGridLayout->addWidget(m_pLineEdit_Name, 0, 3);

    QLabel *plabelMeetingPoint = new QLabel("交汇口:",this);
    m_pLabel_MeetingPoint = new QLabel(this);
    QLabel *plabelLength = new QLabel("长度:", this);
    m_pLabel_Length = new QLabel(this);
    pGridLayout->addWidget(plabelMeetingPoint, 1, 0);
    pGridLayout->addWidget(m_pLabel_MeetingPoint, 1, 1);
    pGridLayout->addWidget(plabelLength);
    pGridLayout->addWidget(m_pLabel_Length);

    QLabel *plabelRoadType = new QLabel("道路类型:", this);
    m_pCombox_RoadType = new QComboBox(this);
    QStringList strListRoadType;
    strListRoadType << UNKNOWN << COUNTRY << CITY << EXPRESSWAY;
    m_pCombox_RoadType->addItems(strListRoadType);
    m_pCombox_RoadType->setCurrentText(CITY);
    pGridLayout->addWidget(plabelRoadType, 2, 0);
    pGridLayout->addWidget(m_pCombox_RoadType, 2, 1, 1, 2);

    QHBoxLayout *pHBLayoutGridLay = new QHBoxLayout();
    pHBLayoutGridLay->addLayout(pGridLayout);
    pHBLayoutGridLay->addStretch(1);

    m_pPushBtn_BashInfo = new QPushButton("基本信息", this);
    m_pPushBtn_GeometryInfo = new QPushButton("几何信息", this);
    m_pPushBtn_Link = new QPushButton("连接", this);
    m_pPushBtn_Lane = new QPushButton("车道", this);
    m_pPushBtn_MeetingPoint = new QPushButton("交汇口", this);
    QHBoxLayout *pHBLayoutPushBtn = new QHBoxLayout();
    pHBLayoutPushBtn->addWidget(m_pPushBtn_BashInfo);
    pHBLayoutPushBtn->addWidget(m_pPushBtn_GeometryInfo);
    pHBLayoutPushBtn->addWidget(m_pPushBtn_Link);
    pHBLayoutPushBtn->addWidget(m_pPushBtn_Lane);
    pHBLayoutPushBtn->addWidget(m_pPushBtn_MeetingPoint);
    pHBLayoutPushBtn->setSpacing(0);

    m_pStackedWidget = new QStackedWidget(this);
    m_pBashInfo = new BashInfo(this);
    m_pGeometryInfo = new GeometryInfo(this);
    m_pLane  = new Lane(this);
    m_pLink  = new Link(this);
    m_pMeetingPoint = new MeetingPoint(this);
    m_pStackedWidget->addWidget(m_pBashInfo);
    m_pStackedWidget->addWidget(m_pGeometryInfo);
    m_pStackedWidget->addWidget(m_pLane);
    m_pStackedWidget->addWidget(m_pLink);
    m_pStackedWidget->addWidget(m_pMeetingPoint);
    m_pStackedWidget->setCurrentWidget(m_pBashInfo);

    QLabel *pLabelOffset = new QLabel("offset[m]",this);
    pLabelOffset->setFixedHeight(30);
    pLabelOffset->setAlignment(Qt::AlignCenter);
    pLabelOffset->setStyleSheet("QLabel{background-color:rgb(211, 211, 211);}");//设置样式表

    m_pListWidget = new QListWidget(this);
    QVBoxLayout *pVBLayoutOffset = new QVBoxLayout();
    pVBLayoutOffset->addWidget(pLabelOffset);
    pVBLayoutOffset->addWidget(m_pListWidget);

    QHBoxLayout *pHBLayoutWidget = new QHBoxLayout();
    pHBLayoutWidget->addWidget(m_pStackedWidget);
    pHBLayoutWidget->addLayout(pVBLayoutOffset);
    pHBLayoutWidget->setStretchFactor(m_pStackedWidget, 4);
    pHBLayoutWidget->setStretchFactor(pVBLayoutOffset, 1);

    QVBoxLayout *pVBLayout = new QVBoxLayout();
    pVBLayout->addLayout(pHBLayoutGridLay);
    pVBLayout->addLayout(pHBLayoutPushBtn);
    pVBLayout->addLayout(pHBLayoutWidget);

    setLayout(pVBLayout);
}


void PropertiesDialog::initSignalSlot()
{
    connect(m_pPushBtn_BashInfo, SIGNAL(clicked()), this, SLOT(onPushBtn_BashInfo()));
    connect(m_pPushBtn_GeometryInfo, SIGNAL(clicked()), this, SLOT(onPushBtn_GeometryInfo()));
    connect(m_pPushBtn_Lane, SIGNAL(clicked()), this, SLOT(onPushBtn_Lane()));
    connect(m_pPushBtn_Link, SIGNAL(clicked()), this, SLOT(onPushBtn_Link()));
    connect(m_pPushBtn_MeetingPoint, SIGNAL(clicked()), this, SLOT(onPushBtn_MeetingPoint()));
}

void PropertiesDialog::onPushBtn_BashInfo()
{
    m_pStackedWidget->setCurrentWidget(m_pBashInfo);
}

void PropertiesDialog::onPushBtn_Lane()
{
    m_pStackedWidget->setCurrentWidget(m_pLane);
}

void PropertiesDialog::onPushBtn_Link()
{
    m_pStackedWidget->setCurrentWidget(m_pLink);
}

void PropertiesDialog::onPushBtn_GeometryInfo()
{
    m_pStackedWidget->setCurrentWidget(m_pGeometryInfo);
}

void PropertiesDialog::onPushBtn_MeetingPoint()
{
    m_pStackedWidget->setCurrentWidget(m_pMeetingPoint);
}
